<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <img src="./images/1.webp" alt="" />
    <script>
      //声明一个数组  储存图片
      let imgArr = [
        './images/1.webp',
        './images/2.webp',
        './images/3.webp',
        './images/4.webp',
        './images/5.webp',
        './images/6.webp',
      ]
      //生产一个随机数
      let random = Math.floor(Math.random() * imgArr.length)
      // console.log(imgArr.length)
      //选择这个图片
      let pic = document.querySelector('img')
      //随机换一张图片
      pic.src = imgArr[random]
      // console.log(random)
      // pic.src = './images/6.webp'
    </script>
  </body>
</html>
<!-- imgArr[random] -->
